package proxypattern.impl;

import lombok.Getter;
import proxypattern.base.BaseState;
import proxypattern.entity.RemoteGumballMachine;

/**
 * 糖果机已售空状态
 * @author yaojianfeng
 */
public class SoldOutStateImpl implements BaseState {
    @Getter
    private String desc = "糖果机已售罄";
    private transient RemoteGumballMachine gumballMachine;

    /**
     * 我们通过构造器得到糖果机的引用,然后将它记录在实例变量中
     * @param gumballMachine 糖果机对象
     */
    public SoldOutStateImpl(RemoteGumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("请勿投币!糖果机已售空,投币我也不给糖果!");
        gumballMachine.setState(gumballMachine.getHasQuarterState());
    }

    @Override
    public void ejectQuarter() {
        System.out.println("硬币已退还!");
        gumballMachine.setState(gumballMachine.getNoQuarterState());
    }

    @Override
    public void turnCrank() {
        System.out.println("糖果机空空如也!");
    }

    @Override
    public void dispense() {
        System.out.println("真的一颗也没有啦");
    }
}
